﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Rob Ashton 2009
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@mvcex.com
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MvcEx.Configuration;

namespace MvcEx.Theming
{
    public static class MvcExHtmlHelpers
    {
        /// <summary>
        /// Includes any CSS files introduced as a module dependency
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static String IncludeModuleCss(this HtmlHelper helper)
        {
            return string.Empty;
        }

        /// <summary>
        /// Includes any JS introduced as a module dependency
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static String IncludeModuleScript(this HtmlHelper helper)
        {
            return string.Empty;
        }

        /// <summary>
        /// Includes a CSS file as a theme overrideable resource
        /// </summary>
        /// <returns></returns>
        public static string IncludeThemeCss(this HtmlHelper helper, String defaultFile)
        {
            String filepath = MvcExThemePathResolver.ResolveThemeFileLocation(
                MvcExThemeSystem.ThemeSelector.GetActiveTheme(),
                MvcExConstants.THEME_DIRECTORY,
                helper.ViewContext.HttpContext,
                defaultFile);

            // No relative paths for us thanks
            filepath = MvcExThemePathResolver.TidyLinkedResourcePath(helper.ViewContext.HttpContext, filepath);
            
            return string.Format("<link rel=\"Stylesheet\" type=\"text/css\" href=\"{0}\" />\r\n", filepath);
        }

        /// <summary>
        /// Includes a JS file as a theme overrideable resource
        /// </summary>
        /// <returns></returns>
        public static string IncludeThemeJs(this HtmlHelper helper, String defaultFile)
        {
            String filepath = MvcExThemePathResolver.ResolveThemeFileLocation(
            MvcExThemeSystem.ThemeSelector.GetActiveTheme(),
            MvcExConstants.THEME_DIRECTORY,
              helper.ViewContext.HttpContext,
              defaultFile);

            // No relative paths for us thanks
            filepath = MvcExThemePathResolver.TidyLinkedResourcePath(helper.ViewContext.HttpContext, filepath);

            return string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>\r\n", filepath);
        }
    }
}
